<template>
	<section>
		<Row :gutter="10">
			<Card>
				<Row>
					<!--工具条-->
					<el-col :span="23" class="toolbar" id="serachId">
						<el-form :inline="true" :model="filters">
							<el-button type="primary" size="small"  style="float:left;">批量授权</el-button>
							<el-form-item style="float:right">
								<el-button type="primary" size="small" v-on:click="getList">查询</el-button>
							</el-form-item>
							<el-form-item style="float:right">
								<el-input v-model="filters.appName" size="small" placeholder="请输入应用名称" @keyup.enter.native="searchEnterFun"></el-input>
							</el-form-item>
						</el-form>
					</el-col>
				</Row>
			</Card>
			<Card>
				<el-row class="tac">
				<el-col :span="4">
                	<el-tree @check-change="toGetList" node-key="marketCode" ref="tree" :load="loadData" :props="defaultProps_market" lazy show-checkbox></el-tree>
            	</el-col>
				<el-col :span="20" >
					<!--列表-->
					<el-table :data="tableData" highlight-current-row v-loading="listLoading" style="width: 100%;">
						<el-table-column type="index" label="序号" min-width="60">
						</el-table-column>
						<el-table-column prop="appName" label="应用名称">
						</el-table-column>
						<!-- <el-table-column prop="appCode" label="应用编码">//去掉应用编码
						</el-table-column> -->
						<el-table-column prop="marketName" label="所属市场" width="300"><!-- 将字段宽度加长 -->
						</el-table-column>
						<el-table-column prop="className" label="应用分类">
						</el-table-column>
						<!-- <el-table-column prop="appSource" label="应用来源">
						</el-table-column> -->
						<el-table-column prop="createDate" label="创建时间" :formatter="formatCreateDate">
						</el-table-column>
						<!-- <el-table-column prop="updateDate" label="修改时间" :formatter="formatUpdateDate"> 去掉修改
						</el-table-column> -->
						<el-table-column fixed="right" label="操作" min-width="100">
							<template slot-scope="scope">
								<el-button type="text" size="small" @click="authorizationView(scope.$index, scope.row)">编辑/查看授权</el-button>
								<el-button type="text" size="small" @click="versionEdit(scope.$index, scope.row)">版本信息</el-button>
							</template>
						</el-table-column>
					</el-table>
					<!--工具条-->
					<el-col :span="24" class="toolbar">
						<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentPageChange"
										:current-page="pageNum" :page-size="pageSize" :total="total">
						</el-pagination>
					</el-col>
				</el-col>
				</el-row>
				<!-- <el-row type="flex" class="row-bg" justify="end">
					<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentPageChange"
									:current-page="pageNum" :page-size="pageSize" :total="total">
					</el-pagination>
				</el-row> -->
			</Card>

			<el-dialog title="授权管理" :visible.sync="authorizationDig" :modal-append-to-body="false" width="50%">
			<!-- <Modal v-model="authorizationDig" title="授权管理" width='60%'> -->
				<el-container style="height: 450px;">
				<el-card>
				<el-col :span="24">
					<el-button @click="authorizationAdd" style="float:left;" type="primary">新增授权</el-button><!--将新增改为新增授权，样式位蓝色-->
				</el-col>
				<el-main style="height:450px;"> 
				<!--授权管理列表-->
						<el-table :data="authorizationDate" highlight-current-row v-loading="authorizationLoading" style="width: 100%;">
							<el-table-column type="index" label="序号">
							</el-table-column>
							<el-table-column prop="typeName" label="类型">
							</el-table-column>
							<el-table-column prop="name" label="名称">
							</el-table-column>
							<el-table-column prop="AuthName" label="授权人">
							</el-table-column>
							<el-table-column prop="createDate" label="授权时间" :formatter="formatCreateDate">
							</el-table-column>
							<el-table-column fixed="right" label="操作">
								<template slot-scope="scope">
									<el-button type="text" size="small" @click="authorizationDelete(scope.$index, scope.row)">删除</el-button>
								</template>
							</el-table-column>
						</el-table>
					</el-main>
				</el-card>
				</el-container>
				<el-col :span="24" class="toolbar">
					<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentPageChange_authorization"
									:current-page="pageNum_authorization" :page-size="pageSize_authorization" :total="total_authorization">
					</el-pagination>
				</el-col>
				
			
				<!-- <span slot="footer" class="dialog-footer" style="padding: 230px 30px 230px;">
					<el-button @click="authorizationDig = false">取 消</el-button>
				</span> -->
			<!-- </Modal> -->
			</el-dialog>

			<el-dialog title="新增授权" :visible.sync="authorizationAddDig" :modal-append-to-body="false">
				 <el-container style="height: 450px;">  
        		<el-tabs v-model="activeName" @tab-click="handleClick">
            		<el-tab-pane label="部门" name="first">
						<el-row class="tac">
							<el-col :span="4">
								<el-tree @node-click="toGetBmList" :data="bmtreeData" node-key="orgSerialNo" ref="bmtree"
										highlight-current :props="defaultProps_bm">
								</el-tree>
							</el-col>
							<el-col :span="20">
								<el-main style="height:360px">
								<el-table :data="bmtableData" highlight-current-row v-loading="bmListLoading" style="width: 100%;" @selection-change="addSelsChange">
									<el-table-column type="selection" width="55" :selectable="selectable">
									</el-table-column>
									<el-table-column prop="name" label="部门名称" min-width="200">
									</el-table-column>
									<el-table-column prop="parentOrganizationName" label="上级部门" min-width="120">
									</el-table-column>
									<!-- <el-table-column prop="orgNum" label="部门编码" min-width="120"> 去掉部门编码
									</el-table-column> -->
								</el-table>
								</el-main>
								<!--工具条-->
								<el-col :span="24" class="toolbar">
									<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentPageChange_bm"
													:current-page="pageNum_bm" :page-size="pageSize_bm" :total="total_bm">
									</el-pagination>
								</el-col>
							</el-col>
						</el-row>
					</el-tab-pane>
					<el-tab-pane label="角色" name="second">
						<el-row class="tac">
							<el-col :span="24">
								<el-main style="height:360px">
								<el-table :data="jstableData" highlight-current-row v-loading="jsListLoading" style="width: 100%;" @selection-change="addSelsChange">
									<el-table-column type="selection" width="55" :selectable="selectable">
									</el-table-column>
									<el-table-column prop="roleName" label="角色名称" min-width="200">
									</el-table-column>
									<el-table-column prop="serialNo" label="角色编码" min-width="200">
									</el-table-column>
									<el-table-column prop="type" label="角色类型" min-width="120">
									</el-table-column>
									<el-table-column prop="isDefault" label="是否默认角色" min-width="120">
									</el-table-column>
								</el-table>
								</el-main>
								<!--工具条-->
								<el-col :span="24" class="toolbar">
									<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentPageChange_js"
													:current-page="pageNum_js" :page-size="pageSize_js" :total="total_js">
									</el-pagination>
								</el-col>
							</el-col>
						</el-row>
					</el-tab-pane>
					<el-tab-pane label="警种" name="third">
						<el-row class="tac">
							<el-col :span="24">
								<el-main style="height:360px">
								<el-table :data="jztableData" highlight-current-row v-loading="jzListLoading" style="width: 100%;" @selection-change="addSelsChange">
									<el-table-column type="selection" width="55" :selectable="selectable">
									</el-table-column>
									<el-table-column prop="name" label="职业类别" min-width="200">
									</el-table-column>
								</el-table>
								</el-main>
								<!--工具条-->
								<el-col :span="24" class="toolbar">
									<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentPageChange_jz"
													:current-page="pageNum_jz" :page-size="pageSize_jz" :total="total_jz">
									</el-pagination>
								</el-col>
							</el-col>
						</el-row>
					</el-tab-pane>
					<el-tab-pane label="用户" name="four">
						
						<el-row>
							<!--工具条-->
							<el-col :span="23" class="toolbar" id="serachId">
								<el-form :inline="true" :model="filters">
									<el-form-item style="float:right">
										<el-button type="primary" size="small" v-on:click="toGetUserList">查询</el-button>
									</el-form-item>
									<el-form-item style="float:right">
										<el-input v-model="filters.name" size="small" placeholder="请输入用户名称"></el-input>
									</el-form-item>
								</el-form>
							</el-col>
						</el-row>
						<el-main style="height:340px">
						<el-row class="tac">
							<el-col :span="24">
								<el-table :data="usertableData" highlight-current-row v-loading="userListLoading" style="width: 100%;" @selection-change="addSelsChange">
									<el-table-column type="selection" width="55" :selectable="selectable">
									</el-table-column>
									<el-table-column prop="name" label="姓名" min-width="200">
									</el-table-column>
									<el-table-column prop="orgName" label="所属部门" min-width="200">
									</el-table-column>
									<!--<el-table-column prop="type" label="用户类型" min-width="200">
									</el-table-column>-->
									<el-table-column prop="jobTypeName" label="职务类别" min-width="200">
									</el-table-column>
								</el-table>
								
							</el-col>
						</el-row>
						</el-main>
						<!--工具条-->
								<el-col :span="24" class="toolbar">
									<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentPageChange_user"
													:current-page="pageNum_user" :page-size="pageSize_user" :total="total_user">
									</el-pagination>
								</el-col>
					</el-tab-pane>
				</el-tabs>
				 </el-container>
				<span slot="footer" class="dialog-footer">
					<el-button @click="authorizationAddDig = false">取 消</el-button>
					<el-button type="primary" @click="authorizationAddSubmit" :disabled="this.addSels.length===0">提 交</el-button>
				</span>
			</el-dialog>


			<!-- 版本信息 -->
			<el-dialog title="版本信息"  :visible.sync="versionDialogVisible" :modal-append-to-body="false">
				<el-form :model="versionTab" ref="versionTab"  >
				<el-tabs v-model="activeTab" @tab-click="handleClick2">
					<el-tab-pane label="Web" name="first">
					<el-col  >
						<el-table  :data="webTableList" highlight-current-row v-loading="webListLoading"   >
						<!-- <el-table-column type="selection" >
						</el-table-column> -->
						<el-table-column prop="appName"  label="应用名称" >
						</el-table-column>
						<!-- <el-table-column prop="appCode" label="应用编码" >
						</el-table-column> -->
						<!-- <el-table-column prop="versionType" label="版本类型" :formatter="formatVersion">
						</el-table-column> -->
						<el-table-column prop="version" label="版本号">
						</el-table-column>
						<el-table-column prop="publishDate" label="发布时间" :formatter="formatPublishDate">
						</el-table-column>
						<el-table-column prop="currentVersion" label="当前版本" :formatter="formatCurrentVersion">
						</el-table-column>
						<el-table-column prop="creater" label="创建人">
						</el-table-column>
						<el-table-column prop="updateDate" label="修改时间" :formatter="formatUpdateDate">
						</el-table-column>
						<!-- <el-table-column fixed="right" label="操作" width="150">
						<template slot-scope="scope">
						<el-button @click="view(scope.$index, scope.row)" type="text" size="small">查看</el-button>
						<el-button @click="putDown(scope.$index, scope.row)" v-if="scope.row.currentVersion === 1" type="text" size="small">下架</el-button>
						<el-button @click="check(scope.$index, scope.row)" type="text" size="small" v-else>设为当前版本</el-button>
						</template>
						</el-table-column> -->
					</el-table>
					</el-col>
					<el-col :span="24" class="toolbar">
					<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentWebPageChange"
									:current-page="webPageNum" :page-size="pageSize" :total="webTotal">
					</el-pagination>
					</el-col>
					</el-tab-pane>
					<el-tab-pane label="IOS" name="second">
					<el-col  >
						<el-table :data="iosTableList" highlight-current-row v-loading="iosListLoading"   >
						<!-- <el-table-column type="selection" >
						</el-table-column> -->
						<el-table-column prop="appName"  label="应用名称" >
						</el-table-column>
						<el-table-column prop="appCode" label="应用编码" >
						</el-table-column>
						<el-table-column prop="versionType" label="版本类型" :formatter="formatVersion">
						</el-table-column>
						<el-table-column prop="version" label="版本号">
						</el-table-column>
						<el-table-column prop="currentVersion" label="当前版本" :formatter="formatCurrentVersion">
						</el-table-column>
						<el-table-column prop="creater" label="创建人">
						</el-table-column>
						<el-table-column prop="updateDate" label="修改时间" :formatter="formatUpdateDate">
						</el-table-column>
						<!-- <el-table-column fixed="right" label="操作" width="150">
						<template slot-scope="scope">
						<el-button @click="view(scope.$index, scope.row)" type="text" size="small">查看</el-button>
						<el-button @click="putDown(scope.$index, scope.row)" v-if="scope.row.currentVersion === 1" type="text" size="small">下架</el-button>
						<el-button @click="check(scope.$index, scope.row)" type="text" size="small" v-else>设为当前版本</el-button>
						</template>
						</el-table-column> -->
					</el-table>
					</el-col>
					<el-col  class="toolbar">
					<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentIosPageChange"
									:current-page="iosPageNum" :page-size="pageSize" :total="iosTotal">
					</el-pagination>
					</el-col>
					</el-tab-pane>
					<el-tab-pane label="Android" name="third">
					<el-col  >
						<el-table :data="androidTableList" highlight-current-row v-loading="androidListLoading"  >
						<!-- <el-table-column type="selection" >
						</el-table-column> -->
						<el-table-column prop="appName"  label="应用名称" >
						</el-table-column>
						<el-table-column prop="appCode" label="应用编码" >
						</el-table-column>
						<el-table-column prop="versionType" label="版本类型" :formatter="formatVersion">
						</el-table-column>
						<el-table-column prop="version" label="版本号">
						</el-table-column>
						<el-table-column prop="currentVersion" label="当前版本" :formatter="formatCurrentVersion">
						</el-table-column>
						<el-table-column prop="creater" label="创建人">
						</el-table-column>
						<el-table-column prop="updateDate" label="修改时间" :formatter="formatUpdateDate">
						</el-table-column>
						<!-- <el-table-column fixed="right" label="操作" width="150">
						<template slot-scope="scope">
						<el-button @click="view(scope.$index, scope.row)" type="text" size="small">查看</el-button>
						<el-button @click="putDown(scope.$index, scope.row)" v-if="scope.row.currentVersion === 1" type="text" size="small">下架</el-button>
						<el-button @click="check(scope.$index, scope.row)" type="text" size="small" v-else>设为当前版本</el-button>
						</template>
						</el-table-column> -->
					</el-table>
					</el-col>
					<el-col :span="24" class="toolbar">
					<el-pagination layout="total, prev, pager, next, jumper" @current-change="handleCurrentAndroidPageChange"
									:current-page="androidPageNum" :page-size="pageSize" :total="androidTotal">
					</el-pagination>
					</el-col>
					</el-tab-pane>
				</el-tabs>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="versionDialogVisible = false">取 消</el-button>
					<!-- <el-button type="primary" @click="versionDialogVisible = false">确 定</el-button> -->
				</span>
			</el-dialog>
		</Row>
	</section>
</template>

<script>

	import Vue from 'vue';
	import iviewArea from 'iview-area';
	Vue.use(iviewArea);

	import util from '../api/util'
	//import NProgress from 'nprogress'
	import { getMarketList,marketAuthorizationSearch,marketNotPageSerach,marketAuthorizationDelete,marketAuthorizationCreate,marketPublishSearch,marketOrgTree,marketOrgSearch2,
				marketRoleSearch,marketPoliceSearch,getDictionaryList,marketUserSearch, deletesupplierAllocationByUser,versionList,getRoleList } from '../../api/api';

	export default {
		data() {
			return {
				filters: {
					appName: '',
					name:''
				},
				tableData: [],
				total: 0,
				pageNum: 1,
				pageSize:5,
				listLoading: false,

				//授权页面显示
				authorizationDig:false,
				authorizationLoading:false,
				total_authorization: 0,
				pageNum_authorization: 1,
				pageSize_authorization:5,
				authorizationDate:[],
				//授权新增
				authorizationAddDig:false,
				authorizationAddLoading: false,

				addSels:[],//列表选中列5
				submitype:0,//默认为1：部门列表选择提交；2：角色列表选择提交；3：警种类别选择提交；4：用户类别选择提交
				marketCode:null,
				appCode:null,
				//授权新增 部门
				activeName: 'first',
				bmtreeData:[],
				bmtableData:[],
				bmListLoading: false,
				total_bm: 0,
				pageNum_bm: 1,
				pageSize_bm:5,
				//授权新增 角色
				jstableData:[],
				jsListLoading: false,
				total_js: 0,
				pageNum_js: 1,
				pageSize_js:5,
				//授权新增 角色
				jztableData:[],
				jzListLoading: false,
				total_jz: 0,
				pageNum_jz: 1,
				pageSize_jz:5,
				//授权新增 用户
				usertableData:[],
				userListLoading: false,
				total_user: 0,
				pageNum_user: 1,
				pageSize_user:5,

            	resDefault: [],
				showRes: [],
				defaultProps_market: {
					label: 'marketName',
					isLeaf: 'leaf',
				},
				defaultProps_bm: {
					id:'orgSerialNo',
					label: 'name',
					children: 'organizationVos',
				},
				notResultData:[],

				// =====================================版本信息===================================
				activeTab: 'first',
				versionDialogVisible: false,
				versionTab:{
					appCode:'',
				},
				webTotal: 0,
				webPageNum: 1,
				webPageSize:2,
				iosTotal: 0,
				iosPageNum: 1,
				iosPageSize:2,
				androidTotal: 0,
				androidPageNum: 1,
				androidPageSize:2,
				webListLoading: false,
				iosListLoading: false,
				androidListLoading: false,
				webTableList:[],
				webLists:[],
				iosTableList:[],
				androidTableList:[],
			}
		},
		methods: {
			formatCreateDate: function (row, column) {
				return row.createDate = (!row.createDate || row.createDate == '') ? '' : util.formatDate.format(new Date(row.createDate), 'yyyy-MM-dd hh:mm');
			},
			formatUpdateDate: function (row, column) {
				return row.updateDate = (!row.updateDate || row.updateDate == '') ? '' : util.formatDate.format(new Date(row.updateDate), 'yyyy-MM-dd hh:mm');
			},
			formatPublishDate: function (row, column) {
				return row.publishDate = (!row.publishDate || row.publishDate == '') ? '' : util.formatDate.format(new Date(row.publishDate), 'yyyy-MM-dd hh:mm:ss');
			},
			handleCurrentPageChange: function (pageNum) {// 翻页动作
				this.pageNum = pageNum;
				this.getList();// 翻页后刷新页面数据
			},
			handleCurrentPageChange_authorization: function (pageNum) {// 翻页动作
                this.pageNum = pageNum;
                this.getList();// 翻页后刷新页面数据
			},
			handleCurrentPageChange_bm: function (pageNum) {// 翻页动作
                this.pageNum_bm = pageNum;
                this.toGetBmList();// 翻页后刷新页面数据
			},
			handleCurrentPageChange_js: function (pageNum) {// 翻页动作
                this.pageNum_js = pageNum;
                this.toGetJsList();// 翻页后刷新页面数据
			},
			handleCurrentPageChange_jz: function (pageNum) {// 翻页动作
                this.pageNum_jz = pageNum;
                this.toGetJzList();// 翻页后刷新页面数据
			},
			handleCurrentPageChange_user: function (pageNum) {// 翻页动作
                this.pageNum_user = pageNum;
                this.toGetUserList();// 翻页后刷新页面数据
			},
			// =====================================版本信息===================================
			handleCurrentWebPageChange: function (webPageNum) {// 翻页动作
				this.webPageNum = webPageNum;
				this.webList();// 翻页后刷新页面数据
			},
			handleCurrentIosPageChange: function (iosPageNum) {// 翻页动作
				this.iosPageNum = iosPageNum;
				this.iosList();// 翻页后刷新页面数据
			},
			handleCurrentAndroidPageChange: function (androidPageNum) {// 翻页动作
				this.androidPageNum = androidPageNum;
				this.androidList();// 翻页后刷新页面数据
			},
			// =======================================版本信息结束===============================
			marketNotPageSerach() {
				let params = {
					appCode: this.appCode,
					marketCode: this.marketCode
				};
				marketNotPageSerach(params).then(function(result){
					this.notResultData = result.data.list;
				}.bind(this)).catch(function (error) {
				}.bind(this));
			},
			selectable:function(row,index){
				let bln = true;
				this.notResultData.forEach(obj => {
					if(row.orgSerialNo === obj.orgSerialNo){
						bln = false;
						return
					}else if(row.id === obj.roleId) {
						bln = false;
						return
					}else if(row.id === obj.police) {
						bln = false;
						return
					}else if(row.userId === obj.userId) {
						bln = false;
						return
					}
				});
				return bln;
			},
			//实现回车键搜索功能
			searchEnterFun:function(e){
				this.getList();
            },
			//获取列表
			getList() {
				let keys = this.$refs.tree.getCheckedKeys();
				let marketCodes =  [];
				keys.forEach(obj => {
					marketCodes.push(parseInt(obj));
				});
				let params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					appName: this.filters.appName,
					marketCodes:marketCodes
				};
				this.listLoading = true;
				//NProgress.start();
				marketPublishSearch(params).then(function(result){
					this.tableData = result.data.list;
					this.pageNum = result.data.pageNum;
					this.pageSize = result.data.pageSize;
					this.total = result.data.total;
					this.listLoading = false;
				}.bind(this)).catch(function (error) {
					this.listLoading = false;
					console.log(error);
				}.bind(this));
			},
			//授权管理页面
			authorizationView: function (index, row) {
				this.authorizationDig = true;
				this.marketCode = row.marketCode;
				this.appCode = row.appCode;
				let params = {
					pageNum: this.pageNum_authorization,
					pageSize: this.pageSize_authorization,
					appCode: this.appCode,
					marketCode: this.marketCode
				};
				this.marketNotPageSerach();
				this.authorizationLoading = true;
				//NProgress.start();
				marketAuthorizationSearch(params).then(function(result){
					this.authorizationDate = result.data.list;
					this.pageNum_authorization = result.data.pageNum;
					this.pageSize_authorization = result.data.pageSize;
					this.total_authorization = result.data.total;
					this.authorizationLoading = false;
				}.bind(this)).catch(function (error) {
					this.authorizationLoading = false;
					console.log(error);
				}.bind(this));
			},
			//删除
			authorizationDelete: function (index, row) {
				let _this = this;
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					_this.authorizationLoading = true;
					marketAuthorizationDelete(row.id).then((res) => {
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						let _params = {
							marketCode: _this.marketCode,
							appCode: _this.appCode,
						};
						_this.authorizationLoading = false;
						_this.authorizationView(1,_params);
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},
			//    =====授权新增=====
			handleClose(done) {
				this.$confirm('确认关闭？')
				.then(_ => {
					done();
				})
				.catch(_ => {});
			},
			handleClick(tab, event) {
				if(tab.name === 'first'){
					// 根据当前页签改变提交类别（部门）
					this.submitype = 1;
					this.addSels = [];
					// 加载tree和部门列表
					this.getbmtree();
					this.toGetBmList();
				}else if(tab.name === 'second'){
					// 根据当前页签改变提交类别（角色）
					this.submitype = 2;
					this.addSels = [];
					// 加载角色列表
					this.toGetJsList();
				}else if(tab.name === 'third'){
					// 根据当前页签改变提交类别（警种）
					this.submitype = 3;
					this.addSels = [];
					// 加载警种列表
					this.toGetJzList();
				}else if(tab.name === 'four'){
					// 根据当前页签改变提交类别（用户）
					this.submitype = 4;
					this.addSels = [];
					// 加载用户列表
					this.toGetUserList();
				}
			},
			authorizationAdd: function() {
				// 重新初始化
				this.bmtreeData = [];
				this.bmtableData = [];
				this.jstableData = [];
				this.jztableData = [];
				this.usertableData = [];
				this.activeName = "first";

				let _this = this;
				this.authorizationAddDig = true;
				setTimeout(function(){
					_this.submitype = 1;
					_this.addSels = [];
					_this.getbmtree();
					_this.toGetBmList();
				},100)
			},
			// 部门列表选中列
			addSelsChange: function (addSels) {
				this.addSels = addSels;
			},
			toGetBmList: function() {
				let params = {
					pageNum: this.pageNum_bm,
					pageSize: this.pageSize_bm,
					marketCode:this.marketCode,
					orgSerialNo:this.$refs.bmtree.getCurrentKey()
				};
				this.bmListLoading = true;
				//NProgress.start();
				marketOrgSearch2(params).then(function(result){
					if(result.data.data != null){
						this.bmtableData = result.data.data.list;
						this.pageNum_bm = result.data.data.pageNum;
						this.pageSize_bm = result.data.data.pageSize;
						this.total_bm = result.data.data.total;
					}
					this.bmListLoading = false;
				}.bind(this)).catch(function (error) {
					this.bmListLoading = false;
					console.log(error);
				}.bind(this));
			},
			toGetJsList: function() {
				let params = {
					pageNum: this.pageNum_js,
					pageSize: this.pageSize_js,
					marketCode:this.marketCode
				};
				this.jsListLoading = true;
				//NProgress.start();
				// marketRoleSearch(params).then(function(result){
                getRoleList(params).then(function(result){
					if(result.data.data != null){
						// this.jstableData = result.data.data.list;
						// 大概是这个地方，
                        this.jstableData = result.data.data.list;
						this.pageNum_js= result.data.data.pageNum;
						this.pageSize_js = result.data.data.pageSize;
						this.total_js = result.data.data.total;
					}
					this.jsListLoading = false;
				}.bind(this)).catch(function (error) {
					this.jsListLoading = false;
					console.log(error);
				}.bind(this));
			},
			toGetJzList: function() {
				let params = {
					pageNum: this.pageNum_jz,
					pageSize: this.pageSize_jz,
                    type:"jobCategory",
					// marketCode:this.marketCode
				};
				this.jzListLoading = true;
				//NProgress.start();
				// marketPoliceSearch(params).then(function(result){
                getDictionaryList(params).then(function(result){
					if(result.data.data != null){
					    debugger
						this.jztableData = result.data.data.list;
						this.pageNum_jz= result.data.data.pageNum;
						this.pageSize_jz = result.data.data.pageSize;
						this.total_jz = result.data.data.total;
					}
					this.jzListLoading = false;
				}.bind(this)).catch(function (error) {
					this.jzListLoading = false;
					console.log(error);
				}.bind(this));
			},
			toGetUserList: function() {
				let params = {
					pageNum: this.pageNum_user,
					pageSize: this.pageSize_user,
					marketCode:this.marketCode,
					name:this.filters.name
				};
				this.userListLoading = true;
				//NProgress.start();
				marketUserSearch(params).then(function(result){
					if(result.data.data != null){
						this.usertableData = result.data.data.list;
						this.pageNum_user= result.data.data.pageNum;
						this.pageSize_user = result.data.data.pageSize;
						this.total_user = result.data.data.total;
					}
					this.userListLoading = false;
				}.bind(this)).catch(function (error) {
					this.userListLoading = false;
					console.log(error);
				}.bind(this));
			},
			//授权
			authorizationAddSubmit: function() {
				let _this = this;
				let authorizationArr = [];
				let authorizationType = 0;
				// 部门
				if(this.submitype === 1){
					authorizationArr = this.addSels.map(item => item.orgSerialNo);
					authorizationType = 1;
				}
				// 角色
				if(this.submitype === 2){
					authorizationArr = this.addSels.map(item => item.id);
					authorizationType = 2;
				}
				// 警种
				if(this.submitype === 3){
					authorizationArr = this.addSels.map(item => item.id);
					authorizationType = 3;
				}
				// 用户
				if(this.submitype === 4){
					authorizationArr = this.addSels.map(item => item.userId);
					authorizationType = 4;
				}

				this.$confirm('确认要分配选中的记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					//NProgress.start();
					let params = {
						appCode:_this.appCode,
						marketCode:_this.marketCode,
						authorizationArr:authorizationArr,
						type:authorizationType
					};
					marketAuthorizationCreate(params).then((res) => {
						//NProgress.done();
						_this.$message({
							message: '分配成功',
							type: 'success'
						});
						_this.authorizationAddLoading = false;
						_this.pageNum_authorization = 1;
						_this.addSels = [];
						let row = {
							marketCode: this.marketCode,
							appCode: this.appCode
						};
						_this.authorizationView(0,row);
						_this.authorizationAddDig = false;
					});
				}).catch(() => {
					_this.authorizationAddLoading = false;
				});
			},
			//获取tree
			getbmtree() {
                let params = {
					marketCode:this.marketCode
				};
                marketOrgTree(params).then(function(result){
					if(result.data.length != null){
						this.bmtreeData = result.data;
					}
                }.bind(this)).catch(function (error) {
                }.bind(this));
			},
			//加载tree
			toGetList:function(){
				this.getList();
			},
			//加载tree
			loadData(node,resolve){
				let rootName = '应用市场';
				if(node.level ===0){
					resolve([{marketName:rootName}]);
					return;
				}
				if(node.data.marketName===rootName){
					let params ={
						marketName:'',
					}
					getMarketList(params).then(res => {
						res.data.list.map(item=>{item.leaf=true;});
						resolve(res.data.list);
					}).catch(function (error) {
						this.$message.warning('系统异常 ');
					});
					return;
				}
				return;
			},


			// ==========================================================版本信息==========================
			formatVersion: function (row, column) {
				return row.versionType == 1 ? 'Web' : row.versionType == 2 ? 'IOS' : row.versionType == 3 ? 'Android':'';
			},
			formatCurrentVersion: function (row, column) {
				return row.currentVersion == 1 ? '是' : row.currentVersion == 0 ? '否' : '';
			},
			handleClick2(tab, event) {
				console.log(tab, event);
			},
			versionEdit: function (index, row) {//版本信息弹框
				this.versionDialogVisible = true;
				this.versionTab = Object.assign({}, row);
				this.versionTab.appCode= row.appCode;
				this.webList();
				this.iosList();
				this.androidList();
			},
			webList() {//加载Web 列表
				let params = {
					pageNum: this.webPageNum,
					pageSize:this.webPageSize,
					appCode:this.versionTab.appCode,
					versionType:1,
					currentVersion:1
				};
				this.webListLoading = true;
				//NProgress.start();
				versionList(params).then(function(result){
					this.webTableList = result.data.list;
					this.webPageNum = result.data.pageNum;
					this.webPageSize = result.data.pageSize;
					this.webTotal = result.data.total;
					this.webListLoading = false;
				}.bind(this)).catch(function (error) {
					this.webListLoading = false;
					console.log(error);
				}.bind(this));
			},
			iosList() {
				let params = {
					pageNum: this.iosPageNum,
					pageSize:this.iosPageSize,
					appCode:this.versionTab.appCode,
					versionType:2,
					currentVersion:1
				};
				this.iosListLoading = true;
				//NProgress.start();
				versionList(params).then(function(result){
					this.iosTableList = result.data.list;
					this.iosPageNum = result.data.pageNum;
					this.iosPageSize = result.data.pageSize;
					this.iosTotal = result.data.total;
					this.iosListLoading = false;
				}.bind(this)).catch(function (error) {
					this.iosListLoading = false;
					console.log(error);
				}.bind(this));
			},
			androidList() {
				let params = {
					pageNum: this.androidPageNum,
					pageSize:this.androidPageSize,
					appCode:this.versionTab.appCode,
					versionType:3,
					currentVersion:1
				};
				this.androidListLoading = true;
				//NProgress.start();
				versionList(params).then(function(result){
					this.androidTableList = result.data.list;
					this.androidPageNum = result.data.pageNum;
					this.androidPageSize = result.data.pageSize;
					this.androidTotal = result.data.total;
					this.androidListLoading = false;
				}.bind(this)).catch(function (error) {
					this.androidListLoading = false;
					console.log(error);
				}.bind(this));
			},
		},
		watch: {
			res1 (val) {
				this.showRes = val;
			},
			resDefault (val) {
				this.showRes = val;
			}
    	},
		mounted() {
			this.getList();
		}
	}

</script>
